/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *	  http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.milib.dbg.view.content.graph {
	import com.googlecode.milib.base.IMLBroadcasterListener;
	import com.googlecode.milib.dbg.view.content.AbstractMLDBGWindowContent;
	import com.googlecode.milib.vo.MLEventInfo;

	import flash.display.MovieClip;

	/**
	 * @author Marek Brun
	 */
	public class MLDBGraphContentView extends AbstractMLDBGWindowContent implements IMLBroadcasterListener {

		private var model:IMLDBGGraphModel;
		private var graph:MLDBGGraphView;
		
		public function MLDBGraphContentView(name:String) {
			super(new MovieClip(), name);
			graph=new MLDBGGraphView();
			mlmc.mc.addChild(graph.mc);
		}

		override protected function doSetupScroller():void {
			//scroller.setScrolled(mltf);
		}
		
		override protected function drawData():void {
			graph.setMax(model.getMax());			graph.drawData(model.getData());
			graph.setText(model.getTextData());
		}
		
		override protected function doSize():void {
			graph.setSize(width, height);
		}

		override protected function doIsEnabled():void {
			model.addListener(this);
		}
		
		override protected function doIsDisabled():void {
			model.removeListener(this);
		}
		
		public function setModel(model:IMLDBGGraphModel):void {
			if(this.model){ this.model.removeListener(this); }
			this.model=model;
			if(isEnabled){
				this.model.addListener(this);
				drawData();
			}
		}
		
//********************************************************************************************
//		events for MLDBGMemoryMonitorView
//********************************************************************************************
		public function onEvent(ev:MLEventInfo):void {
			switch(ev.hero){
				case model:
					switch(ev.event) {
						case model.event_Updated:
							drawData();
						break;
					}
				break;
			}
		}
		
	}
}
